/****************************************************************************************************************************************************************
 *                                                                                                                                                              *
 *                                                                                                                                                              *
 *                                                                                                                                                              *
 *                                                                                                                                                              *
 *                      _____  ___________                   ___    ______      ______           _____     _______________________                              *
 *                      __  / / /__  /_  /_____________ _    __ |  / /__(_)________  /_____________  /_    ___    |_____/_/__  __ \                             *
 *                      _  / / /__  /_  __/_  ___/  __ `/    __ | / /__  /_  __ \_  /_  _ \_  __ \  __/    __  /| |___/_/ __  / / /                             *
 *                      / /_/ / _  / / /_ _  /   / /_/ /     __ |/ / _  / / /_/ /  / /  __/  / / / /_      _  ___ |_/_/   _  /_/ /                              *
 *                      \____/  /_/  \__/ /_/    \__,_/      _____/  /_/  \____//_/  \___//_/ /_/\__/      /_/  |_/_/     /_____/                               *
 *                                                                                                                                                              *
 *                                                                                                                                                              *
 *                                                                                                                                                              *
 *                                                                                                                                                              *
 *                                                                                                                                                              *
 *      @Project: Ultra Violent - Attack and Defend                                                                                                             *
 *                                                                                                                                                              *
 *                                                                                                                                                              *
 *      @Author: Daniel "thiaZ" Koenen                                                                                                                          *
 *          @Used content                                                                                                                                       *
 *              @sscanf Plugin, foreach, Whirlpool Plugin, YSI - Y_Less                                                                                         *
 *              @zcmd - Zeex                                                                                                                                    *
 *              @Streamer Plugin, IRC Plugin - Incognito                                                                                                        *
 *              @dini - Dracoblue                                                                                                                               *
 *              @MySQL Plugin - G-sTyLeZzZ                                                                                                                      *
 *          @Special thanks to                                                                                                                                  *
 *              @Slice                                                                                                                                          *
 *                                                                                                                                                              *
 *                                                                                                                                                              *
 *      @File: uvaad.pwn - Main File                                                                                                                            *
 *                                                                                                                                                              *
 *                                                                                                                                                              *
 *      @This file is not released under any open source licence, you are not allowed to own this file except you have the author's permission.                 *
 *                                                                                                                                                              *
 *                                                                                                                                                              *
 *      @copyright (c) Daniel "thiaZ" Koenen 2010 - 2011 - danielkoenen@t-online.de                                                                             *
 *                                                                                                                                                              *
 ****************************************************************************************************************************************************************/          

Hook:CDM_OnGameModeInit()
{
    CDM::load();
    return true;
}
 
stock CDM::load()
{
    for(new i = 0; i < MAX_DMS; i++)
    {
        if(!fexist(CDM::getFile(i)))
        {
            #if DEBUG == true
                printf("[DM] [%d] File does not exist, aborting. (%s)", i, CDM::getFile(i));
            #endif
            break;
        }
        
        INI_ParseFile(CDM::getFile(i), "onDMLoad", false, true, i, true, false);
    }
    
    return;
}

forward onDMLoad(i, name[], value[]);
public  onDMLoad(i, name[], value[])
{   
    if(!strcmp(name, "weapon_0"))
    {
        dMData[i][idmWeapon][0] = strval(value);
        dMData[i][bIsValid] = true;
    }   
    
    if(!strcmp(name, "weapon_1"))
    {
        dMData[i][idmWeapon][1] = strval(value);
    }   
    
    if(!strcmp(name, "interior"))
    {
        dMData[i][xInt] = strval(value);
    }
    
    if(strfind(name, "spawn_") != -1)
    {
        new iSpawn = strval(name[6]);
        sscanf(value, "p<,>ffff", dMData[i][dm_X][iSpawn], dMData[i][dm_Y][iSpawn], dMData[i][dm_Z][iSpawn], dMData[i][dm_A][iSpawn]);
    }
    
    #if DEBUG == true
        printf("[DM] [%d] %s with value %s.", i, name, value);
    #endif
    
    return true;
}

stock CDM::getFile(_iDMID) {
    new _sPath[64];
    format(_sPath, 64, "/Uv_AAD/Deathmatches/%d.ini", _iDMID);
    return _sPath;
}

stock CDM::playerSet(playerid, DMid) {
    new iRdom = random(10);
    SetPlayerPos(playerid, dMData[DMid][dm_X][iRdom],  dMData[DMid][dm_Y][iRdom], dMData[DMid][dm_Z][iRdom]);
    SetPlayerFacingAngle(playerid, dMData[DMid][dm_A][iRdom]);
    SetPlayerVirtualWorld(playerid, 1337 + DMid);
    SetPlayerInterior(playerid, dMData[DMid][xInt]);
    
    SetPlayerHealth(playerid, 100.0);
    SetPlayerArmour(playerid, 100.0);
    
    ResetPlayerWeapons(playerid);
    GivePlayerWeapon(playerid, dMData[DMid][idmWeapon][0], 9999);
    GivePlayerWeapon(playerid, dMData[DMid][idmWeapon][1], 9999);
    playerData[playerid][activeDM] = DMid;
    CPlayer::UpdatePlayerColor(playerid);
}

stock CDM::getPlayerDM(playerid) {
    return playerData[playerid][activeDM];
}

stock bool:CDM::isValidDM(DMid) {
    return dMData[DMid][bIsValid];
}